#include "DVRCommonPCH.h"
#include "DVRUtils.h"

//**************************************************************************************************
//FUNCTION:
void outputInfo(const std::string& vInfo)
{
	std::cout << vInfo << std::endl;
}

//**************************************************************************************************
//FUNCTION:
bool outputWarning(const std::string& vLoc, const std::string& vWarningInfo)
{
	std::cerr << vLoc << vWarningInfo << std::endl;
	return false;
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::vec4& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ", " << vVector.z << ", " << vVector.w << ")";
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::vec3& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ", " << vVector.z << ")";
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::vec2& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ")";
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::dvec4& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ", " << vVector.z << ", " << vVector.w << ")";
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::dvec3& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ", " << vVector.z << ")";
}

//**************************************************************************************************
//FUNCTION:
std::ostream& operator<<(std::ostream& vOutStream, const glm::dvec2& vVector)
{
	return vOutStream << "(" << vVector.x << ", " << vVector.y << ")";
}

//**************************************************************************************************
//FUNCTION:
std::istream& operator>>(std::istream& vInStream, glm::uvec3& vVector)
{
	return vInStream >> vVector.x >> vVector.y >> vVector.z;
}

//**************************************************************************************************
//FUNCTION:
std::istream& operator>>(std::istream& vInStream, glm::vec4& vVector)
{
	return vInStream >> vVector.x >> vVector.y >> vVector.z >> vVector.w;
}

//**************************************************************************************************
//FUNCTION:
std::istream& operator>>(std::istream& vInStream, glm::vec3& vVector)
{
	return vInStream >> vVector.x >> vVector.y >> vVector.z;
}

//**************************************************************************************************
//FUNCTION:
std::istream& operator>>(std::istream& vInStream, glm::vec2& vVector)
{
	return vInStream >> vVector.x >> vVector.y;
}

//**************************************************************************************************
//FUNCTION:
bool convert2RawFileName(const std::string& vHeaderPath, std::string& vDirectory, std::string& vVolumeName)
{
	if (vHeaderPath.empty()) return false;

	size_t HeaderFileNameIndexLeft = vHeaderPath.find_last_of("/");
	size_t HeaderFileNameIndexRight = vHeaderPath.find_last_of("\\");
	size_t DotIndex = vHeaderPath.find_last_of(".");
	size_t HeaderFileNameIndex = 0;
	if ((HeaderFileNameIndexLeft == std::string::npos && HeaderFileNameIndexRight == std::string::npos) || DotIndex == std::string::npos)
		return false;

	if (HeaderFileNameIndexLeft != std::string::npos && HeaderFileNameIndexRight != std::string::npos)
		HeaderFileNameIndex = HeaderFileNameIndexLeft > HeaderFileNameIndexRight ? HeaderFileNameIndexLeft : HeaderFileNameIndexRight;
	HeaderFileNameIndex = HeaderFileNameIndexLeft != std::string::npos ? HeaderFileNameIndexLeft : HeaderFileNameIndexRight;

	vDirectory = vHeaderPath.substr(0, HeaderFileNameIndex + 1);
	vVolumeName = vHeaderPath.substr(HeaderFileNameIndex + 1, DotIndex - HeaderFileNameIndex) + "raw";

	return true;
}
